#include<bits/stdc++.h>
using namespace std;
vector<int> v[1000005];
int n;
long long sum;
int main(){
	freopen("color.in","r",stdin);
	freopen("color.out","w",stdout);
	int t;
	cin>>t;
	while(t--){
		sum=0;
		memset(v,0,sizeof(v));
		cin>>n;
		for(int i = 1;i<=n;i++){
			int x;
			cin>>x;
			if(v[x].size()==1){
				v[x].pop_back();
				sum+=x;
			}
			else v[x].push_back(1);
		}
		cout<<sum<<endl;
	}
	fclose(stdin);
	fclose(stdout);
	return 0;
}
